/**
 * Created by xuqiang on 2018/9/30 0030.
 * @点赞插件
 */

!(function($, win, doc, undefined){

    var defaults = {
        str: "+1",
        startSize: "12px",
        endSize: "30px",
        interval: 600,
        color: "#fa0",
        fontWeight: 'bold'
    };

    function thumbsUp(obj,options){
        this.obj = $(obj);
        this.options = $.extend({}, defaults, options);
        this.init();
    }

    thumbsUp.prototype.constructor = thumbsUp;

    thumbsUp.prototype.init = function(){

        $('body').append('<span class="add-num">' + this.options.str + '</span>');

        var box = $('.add-num');
        var left = this.obj.offset().left + this.obj.width() / 2;
        var top  = this.obj.offset().top - this.obj.height() / 2;

        //设置元素样式
        box.css({
            position: 'absolute',
            top: top + 'px',
            left: left + 'px',
            "z-index": 9999,
            'font-weight': 'bold',
            "font-size": this.options.startSize,
            "line-height": this.options.endSize,
            "color": this.options.color
        });

        //元素过渡动画
        box.animate({
            "font-size": this.options.endSize,
            "opacity": "0",
            "top": top - parseInt(this.options.endSize) + "px"
        },this.options.interval,function(){
            box.remove()
        });

    };

    //把thumbsUp暴露给全局对象
    window.thumbsUp = thumbsUp;

})(jQuery, window, document);